This file is jobs.def, from which is created jobs.c.
It implements the builtin "jobs" in Bash.

Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.

This file is part of GNU Bash, the Bourne Again SHell.

Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.

Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING.  If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

$PRODUCES jobs.c

$BUILTIN jobs
$FUNCTION jobs_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC jobs [-lnp] [jobspec ...]
Lists the active jobs.  The -l option lists process id's in addition
to the normal information; the -p option lists process id's only.
If -n is given, only processes that have changed status since the last
notification are printed.  JOBSPEC restricts output to that job.
$END

#include "../shell.h"

#if defined (JOB_CONTROL)
#include <signal.h>
#include <sys/types.h>
#include "../jobs.h"

extern int job_control;

/* The `jobs' command.  Prints outs a list of active jobs.  If the
   argument `-l' is given, then the process id's are printed also.
   If the argument `-p' is given, print the process group leader's
   pid only.  If `-n' is given, only processes that have changed
   status since the last notification are printed. */
int
jobs_builtin (list)
     WORD_LIST *list;
{
  int form = JLIST_STANDARD;

  if (!job_control)
    return (EXECUTION_SUCCESS);

  while (list && (*list->word->word == '-'))
    {
      if (strcmp (list->word->word, "-l") == 0)
	form = JLIST_LONG;
      else if (strcmp (list->word->word, "-p") == 0)
	form = JLIST_PID_ONLY;
      else if (strcmp (list->word->word, "-n") == 0)
	form = JLIST_CHANGED_ONLY;
      else
	{
	  bad_option (list->word->word);
	  return (EXECUTION_FAILURE);
	}
      list = list->next;
    }

  if (!list)
    {
      list_jobs (form);
      return (EXECUTION_SUCCESS);
    }

  while (list)
    {
      int job;
      sigset_t set, oset;

      BLOCK_CHILD (set, oset);
      job = get_job_spec (list);

      if ((job == NO_JOB) || !jobs || !jobs[job])
	builtin_error ("No such job %s", list->word->word);
      else if (job != DUP_JOB)
	list_one_job ((JOB *)NULL, form, 0, job);

      UNBLOCK_CHILD (oset);
      list = list->next;
    }
    return (EXECUTION_SUCCESS);
}
#endif /* JOB_CONTROL */

